using System;
using System.Windows.Forms;

using FreeFlow.Administration;

namespace FreeFlowAdministrator
{
	/// <summary>
	/// Summary description for MapsAdaptor.
	/// </summary>
	public class MapsAdaptor : Adaptor, IRefreshable
	{
    private MapCollection maps;
		public MapsAdaptor(MapCollection maps)
		{
			this.maps = maps; 
    }

    public override void AddChildren(System.Windows.Forms.TreeNode node)
    {
      foreach (Map map in maps)
      {
        TreeNode childNode = TreeNodeFactory.CreateTreeNode(new MapAdaptor(map));
        node.Nodes.Add(childNode);
      }
    }

    public override int ImageIndex
    {
      get
      {
        return 2;
      }
    }

    public override string Text
    {
      get
      {
        return "Maps (" + maps.Count + ")";
      }
    }

    public override Control GetRenderer()
    {
      MapsControl control = new MapsControl();
      control.LoadMaps(maps);
      control.RefreshRequired += new EventHandler(TriggerRefreshRequired);
      return control;
    }

    public override object Object
    {
      get
      {
        return maps;
      }
    }

    #region IRefreshable Members

    public void Refresh()
    {
      maps.Refresh();
    }

    #endregion
  }
}
